package indi.juzhuohan.chatroom.server;

import java.awt.Color;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import indi.juzhuohan.chatroom.constants.Constants;

/**
 * 在线用户界面
 * 
 * @author 鞠卓瀚
 *
 */
public class Onlineuserpanel {

	private static final String Background_Path = "G:\\java\\chatroom_socket\\src\\indi\\juzhuohan\\chatroom\\client\\chat_background.jpg";

	public JTextPane txtLog;
	public JTextField txtServerName;
	public JTextField txtIP;
	public JTextField txtNumber;

//	类成员用于获取在线用户
	public JList lstUser;

	public JLabel getUserPanel() {
		JPanel pnlUser = new JPanel();
		pnlUser.setLayout(null);
		pnlUser.setBackground(new Color(52, 130, 203));
		pnlUser.setBounds(0, 0, Serverframe.FRAME_WIDTH, Serverframe.FRAME_HEIGHT);
		pnlUser.setOpaque(false);
//		标题
		JLabel lblUser = new JLabel("[在线用户列表]");
		lblUser.setForeground(Color.BLACK);
		lblUser.setFont(new Font("黑体", 0, 16));
		lblUser.setBounds(140, 10, 200, 30);
		pnlUser.add(lblUser);
//		表
		lstUser = new JList();
		lstUser.setFont(new Font("黑体", 0, 14));
		lstUser.setVisibleRowCount(17);
		lstUser.setFixedCellWidth(180);
		lstUser.setFixedCellHeight(18);
		lstUser.setOpaque(false);

		JScrollPane spUser = new JScrollPane(lstUser);
		spUser.setFont(new Font("黑体", 0, 14));
		spUser.setForeground(Color.BLACK);
		spUser.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		spUser.setBounds(140, 40, 340, 350);
		spUser.setOpaque(false);
		pnlUser.add(spUser);
//		壁纸
		ImageIcon imageIcon = new ImageIcon(Background_Path);
		JLabel lblBackground = new JLabel(imageIcon);
		lblBackground.setBounds(0, 200, 300, 300);
		lblBackground.add(pnlUser);

		pnlUser.add(getServerParam());

		return lblBackground;
	}

	public JPanel getServerParam() {
		JPanel serverParamPanel = new JPanel();
		serverParamPanel.setOpaque(false);
		serverParamPanel.setBounds(6, 5, 106, 405);
		serverParamPanel.setFont(new Font("黑体", 0, 14));
		serverParamPanel.setBorder(BorderFactory.createRaisedBevelBorder());
//		当前在线人数
		JLabel lblNumber = new JLabel("当前在线人数：");
		lblNumber.setFont(new Font("黑体", 0, 14));
		serverParamPanel.add(lblNumber);
		txtNumber = new JTextField("0 人", 10);
		txtNumber.setFont(new Font("黑体", 0, 14));
		txtNumber.setEditable(false);
		serverParamPanel.add(txtNumber);
//		服务器名称
		JLabel lblServerName = new JLabel("服务器名称");
		lblServerName.setFont(new Font("黑体", 0, 14));
		serverParamPanel.add(lblServerName);
		txtServerName = new JTextField(10);
		txtServerName.setFont(new Font("黑体", 0, 14));
		txtServerName.setEditable(false);
		serverParamPanel.add(txtServerName);
//		服务器IP
		JLabel lblIP = new JLabel("服务器IP：");
		lblIP.setFont(new Font("黑体", 0, 14));
		serverParamPanel.add(lblIP);
		txtIP = new JTextField(10);
		txtIP.setFont(new Font("黑体", 0, 14));
		txtIP.setEditable(false);
		serverParamPanel.add(txtIP);
//		服务器端口
		JLabel lblPort = new JLabel("服务器端口：");
		lblPort.setFont(new Font("黑体", 0, 14));
		serverParamPanel.add(lblPort);
		JTextField txtPort = new JTextField(Constants.SERVER_PORT + "", 10);
		txtPort.setFont(new Font("黑体", 0, 14));
		txtPort.setEditable(false);
		serverParamPanel.add(txtPort);

		return serverParamPanel;
	}
}
